package com.fessc.develop.handler;

import com.fessc.develop.entity.ccbvo.CCBBankCheckJsonVo;
import com.fessc.develop.handler.processor.send.CCBISendProcessor;
import com.fessc.develop.model.enums.EnumBranch;
import com.fessc.develop.utils.BusiUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Slf4j
@Service
public class CCBBankCheckJsonPushHandler {

    @Resource
    private List<CCBISendProcessor> bankCheckFileProcessors;

    private Map<String, CCBISendProcessor> processorMap;

    @PostConstruct
    public void init() {
        if (BusiUtil.isNotNull(bankCheckFileProcessors)) {
            processorMap = bankCheckFileProcessors.stream().collect(Collectors.toMap(CCBISendProcessor::getProcessorForBranch, p->p, (v1, v2) -> v1));
        } else {
            processorMap = new HashMap<>();
        }
    }

    /**
     * 从建行获取JSON对账结果
     */
    public void ccbBankCheckJsonPush(List<CCBBankCheckJsonVo> ccbBankCheckJsonVoList, String type) {
        CCBISendProcessor processor = processorMap.get(EnumBranch.CCBBANK.toString());
        processor.ccbBankCheckJsonProcess(ccbBankCheckJsonVoList); //对账结果查询推送
    }

}
